package robot;

/**
 * WaveEmoticonsRobotProfile.
 * Servlet that returns a JSON with all the information about the Robot's profile.
 * @author Mirko Bonadei
 * @version 0.2
 *
 */
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Scanner;

import com.google.wave.api.Image;
import com.google.wave.api.ProfileServlet;

public class WaveEmoticonsRobotProfile extends ProfileServlet {

	private static final long serialVersionUID = 6996405709860676117L;
	private static final String PROFILE_FILE = "data" + File.separator + "profile.txt";;
	private static String robotName = "";
	private static String avatarPath = "";
	private static String webPage = "";
	private static FileReader file;
	private static Scanner scan;

	/**
	 * Environmet initialization. The Servlet needs to load the Profile
	 * Information from "profile.txt".
	 */
	static {
		try {
			String tmpCode, tmpPath;
			file = new FileReader(PROFILE_FILE);
			scan = new Scanner(file);
			while (scan.hasNext()) {
				robotName = scan.nextLine();
				avatarPath = scan.nextLine();
				webPage = scan.nextLine();
			}
		} catch (FileNotFoundException ex) {
			// TO DO: Fix this situation with a more reliable exit strategy
			System.out.println(ex.getMessage());
		}
	}

	/**
	 * Returns the Robot Name stored into the Profile file.
	 */
	@Override
	public String getRobotName() {
		return this.robotName;
	}

	/**
	 * Returns the Avatar Path of the Robot stored into the Profile file.
	 */
	@Override
	public String getRobotAvatarUrl() {
		return this.avatarPath;
	}

	/**
	 * Returns the Web Page of the Robot stores into the Web Page.
	 */
	@Override
	public String getRobotProfilePageUrl() {
		return this.webPage;
	}
}
